home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_2 / astronut < prev    next >
Internet Message Format  |  1995-03-31  |  10KB

  1. Path: seq!spell
  2. From: Kevin Jessup <bbwwbb@mixcom.COM>
  3. Subject:  v01i013:  astronut11 - AstroNUT v1.1:  a lunar lander simulation, Part01/01
  4. Newsgroups: comp.sources.hp48
  5. Followup-To: comp.sys.hp48
  6. Approved: spell@seq.uncwil.edu
  7.  
  8. Checksum: 1329276559 (verify with brik -cv)
  9.  
  10. Submitted-by: Kevin Jessup <bbwwbb@mixcom.COM>
  11. Posting-number: Volume 1, Issue 13
  12. Archive-name: astronut11/part01
  13.  
  14. BEGIN_DOC astronut.doc
  15.  
  16.  AstroNUT V1.1
  17.  by Kevin Jessup
  18.  16-May-1991
  19.  Submitted to comp.sources.hp48 on August 6th, 1991
  20.  
  21.  Version 1.1
  22.  -----------
  23.  This version adds a bit of audio and corrects a minor bug:
  24.  flag -19, the COMPLEX MODE flag, is now cleared to insure
  25.  that 2-d vectors are produced when required.  Also, all
  26.  temporary global variables are cleared from the directory
  27.  at the end of play.  (Please allow time for cleanup when
  28.  the game ends: wait for the HP48SX busy indicator to shut
  29.  off.)  Otherwise, the game is the same.
  30.  
  31.  Introduction
  32.  ------------
  33.  AstroNUT is a lunar lander simulation for the 48SX.
  34.  It supports 2-d travel (up, down, left, right) and a
  35.  random terraine that is generated for each new game.
  36.  All routines are in RPL so the screen updates are somewhat
  37.  slow.  I still find play acceptable however.
  38.  
  39.  The object of the game is to land on a more or less flat
  40.  portion of the lunar surface with a horizontal velocity of
  41.  zero and a vertical velocity of less than 5 feet per second.
  42.  (Somewhat fast! Change it if you like.)  You have a limited
  43.  amount of fuel available to do this.
  44.  
  45.  Initial parameters
  46.  ------------------
  47.  Altitude:            170 feet
  48.  
  49.  Vertical velocity:   -20 feet per second.  A "second" is
  50.                       not the usual unit of time that you
  51.                       are familiar with but how long it takes
  52.                       this game to execute it's main loop!
  53.                       You will have to hit the thrust key
  54.                       quite often to slow down.  Read on...
  55.  
  56.  Horizontal velocity: 5 feet per second.  The direction
  57.                       (left or right) is random.  The initial
  58.                       horizontal position is also random.
  59.  
  60.  Fuel:                100 units.  In gallons, liters, cubic
  61.                       light-years or whatever you'd like to
  62.                       call it :-)
  63.  
  64.  Control keys
  65.  ------------
  66.  8: Apply upward thrust (One push equals thrust of 1/2 g)
  67.  
  68.  4: Apply left thrust (Changes horizontal vel. by 1 ft/sec)
  69.  
  70.  6: Apply right thrust (Changes horizontal vel. by 1 ft/sec)
  71.  
  72.  With each screen update, your downward velocity will
  73.  increase due to the acceleration of gravity at a rate of
  74.  4 ft/s^2.  It will require 2 hits of the vertical thrust
  75.  (key 8) to exactly compensate for the acceleration due to
  76.  gravity.
  77.  
  78.  Screen positioning
  79.  ------------------
  80.  As you move to the left and right edges of the display, you
  81.  will wrap around to the opposite side.  There are "unlimited"
  82.  vertical screens.  You will wrap around at the top and bottom.
  83.  When you reach the lowest screen, there will be a slight pause
  84.  as the lunar surface is drawn.  If you move above the lowest
  85.  screen, the surface will be erased.  The current "flight
  86.  parameters" are displayed at the top right of the LCD.
  87.  
  88.  Loading
  89.  -------
  90.  For the neophytes, those funny litle characters at the start
  91.  of these lines are HP48SX comment delimiters.  You can transfer
  92.  this entire file AS IS to your 48.  The 48 will remove all the
  93.  comments and load only the code.
  94.  
  95.  After transferring this file to your 48, recall the directory
  96.  to the stack.  Execute the BYTES command.  You should get the
  97.  following...
  98.  
  99.               Level 2:    #5AB1h
  100.               Level 1:    2707.5
  101.  
  102.  Once you have successfully transferred the directory to your 48,
  103.  just hit PLAY to start.
  104.  
  105.  Be patient...after a little practice, you should be able to
  106.  land using only 100 units of fuel.  You can modify the amount
  107.  of fuel, thrust and acceleration due to gravity if you like.
  108.  Study the code below to find out how.  Have fun!
  109.  
  110.  This is "freeware" but if you'd like to send a few bucks, don't
  111.  let that stop you!
  112.  
  113.  Kevin Jessup
  114.  9118 N 85th
  115.  Milwaukee, WI 53224
  116.  Email address: bbwwbb@mixcom.com
  117.  
  118. END_DOC
  119.  
  120. BYTES: #5AB1h   2720
  121.  
  122. BEGIN_RPL astronut
  123. %%HP: T(3)A(R)F(.);
  124.  
  125. DIR                   @ AstroNUT directory
  126.  
  127.   PLAY                @ push PLAY to start
  128.     \<< RCLF 3 FIX    @ save flags
  129. -19 CF # 83h # 40h    @ create a blank PICT
  130. BLANK PICT STO 1 CF   @ clear the crash flag
  131. 170 'ht' STO          @ set height to 170 feet
  132. -20 'v' STO 5         @ set vertical v to -20
  133.       IF RAND .5 <    @ set horiz v to 5 or -5
  134.       THEN NEG
  135.       END 'hv' STO
  136. RAND 80 * IP 'x'      @ random horiz position
  137. STO 100 'fuel' STO    @ 100 unit of fuel
  138. 2 CF                  @ clear the bottom flag
  139. MAKBOTTOM { # 0h      @ random terrain coordinates
  140. # 0h } PVIEW MAIN     @ display and loop on main
  141. CRASHht 'ht' STO      @ display landing parameters
  142. CRASHx 'x' STO
  143. CRASHv 'v' STO
  144. STATUS PICT NEWC      @ display landing position
  145. SHIP GXOR PICT {      @ display AstroNUT or CRASH
  146. # 5h # 5h }
  147.       IF CRASHv -4    @ test slope, vv and hv
  148. < CRASHsl ABS .084
  149. > OR hv OR
  150.       THEN
  151. "*CRASH*" LOOSE
  152.       ELSE PICT 7
  153. 'ht' STO+ 1 'x'
  154. STO+ NEWC aflag REPL
  155. "AstroNUT" WIN
  156.       END 3 \->GROB
  157. REPL 7 FREEZE         @ freeze the display
  158. globals PURGE         @ purge temporary globals
  159.       WHILE KEY       @ flush any excess keys
  160.       REPEAT DROP
  161.       END STOF        @ restore flags and quit
  162.     \>>
  163.  
  164.   WIN                 @ Play the WIN tune.
  165.     \<< 125           @ "I am not a musician!"
  166.       DO DUP .02
  167. BEEP 2 *
  168.       UNTIL DUP
  169. 4000 >
  170.       END DROP
  171.     \>>
  172.  
  173.   LOOSE               @ Play the LOOSE tune
  174.     \<< 4000
  175.       DO DUP .02
  176. BEEP 2 /
  177.       UNTIL DUP 125
  178. <
  179.       END DROP
  180.     \>>
  181.  
  182.   MAIN                @ main processing loop
  183.     \<<
  184.       DO              @ draw or erase the terraine
  185.         IF ht 56 >
  186.         THEN
  187.           IF 2 FS?
  188.           THEN
  189. ERASE 2 CF
  190.           END
  191.         ELSE
  192.           IF 2 FC?
  193.           THEN
  194. DRAWBOTTOM 2 SF
  195.           END
  196.         END STATUS    @ display flight parameters
  197. NEWC PICT OVER SHIP   @ display the lander
  198. GXOR ht 20 * .01      @ beep based on altitude
  199. BEEP v 'ht' STO+ hv   @ calculate new position
  200. 'x' STO+               
  201.         IF x 124 >    @ wrap horizontal
  202. x 0 < OR
  203.         THEN x 125
  204. MOD ABS 'x' STO
  205.         END
  206. CHKBOTTOM GETKEY ag   @ see if we crashed, process keys
  207. 'v' STO+ PICT SWAP    @ acceleration increases v
  208. SHIP GXOR             @ erase old position
  209.       UNTIL 1 FS?     @ quit if we landed or crashed
  210.       END
  211.     \>>
  212.  
  213. @ CHKBOTTOM is the routine that eats all the CPU time.
  214. @ If anyone knows how to speed it up, please do so.
  215. @ It works by calculating linear regressions and then
  216. @ comparing the line slopes.
  217.  
  218.   CHKBOTTOM           @ set flag 1 if we crashed
  219.     \<< 1 botCOORDS   @ get terraine coordinates list size
  220. SIZE 1 -
  221.       FOR i           @ test each line segment
  222. botCOORDS i GETI 3    @ get line endpoints
  223. ROLLD GET DUP2 1      @ duplicate them
  224. GET SWAP 1 GET        @ get the x coordinates and
  225.         IF x 3 + \<=  @ see if lander is between them
  226. SWAP x 3 + > AND
  227.         THEN OVER     @ if so, compare line slopes
  228. C\->V2 CL\GS \GS+ C\->V2 \GS+ @ calculate line slope
  229. LR x DUP 'CRASHx'     @ calculate and save possible
  230. STO 3 + PREDY         @ crash x and y positions
  231. 'CRASHht' STO SWAP
  232. DROP DUP 'CRASHsl'    @ save crash slope
  233. STO SWAP C\->V2 CL\GS @ calculate slope of line to
  234. \GS+ x 3.001 + ht \->V2 @ the landers coordinates
  235. \GS+ LR SWAP DROP
  236.           IF \>=      @ if line segment slope >= the
  237.           THEN 1 SF   @ slope of line to lander,
  238.  v                    @ we crahed.  Set crash flag.
  239. 'CRASHv' STO 99 'i'   @ save crash velocity
  240. STO
  241.           END
  242.         ELSE DROP2    @ not within this line segment
  243.         END
  244.       NEXT            @ check next line
  245.     \>>
  246.  
  247.   MAKBOTTOM           @ generates a list of coordinates
  248.     \<< { } 0 120     @ get an empty list
  249.       FOR a a RAND    @ generate a random y coordinate
  250. 25 * IP 6 + 2 \->LIST
  251. 1 \->LIST + 12        @ save xy in list, do next
  252.       STEP 130 OVER   @ line up the end points so
  253. 1 GET OBJ\-> DROP     @ we don't impact on wrap
  254. SWAP DROP 2 \->LIST 1
  255. \->LIST + 9 RAND * IP @ insure at least one flat line
  256. 2 + GETI 2 GET 3
  257. ROLLD GETI 2 5 ROLL
  258. PUT SWAP 1 - SWAP
  259. PUT 'botCOORDS' STO   @ save the list
  260.     \>>
  261.  
  262.   DRAWBOTTOM          @ maps terraine coordinates to
  263.     \<< 1 botCOORDS   @ screen and display the lines
  264. SIZE 1 -
  265.       FOR i
  266. botCOORDS i GETI
  267. OBJ\-> ROT R\->B ROT 63
  268. SWAP - R\->B ROT
  269. \->LIST 3 ROLLD GET
  270. OBJ\-> ROT R\->B ROT 63
  271. SWAP - R\->B ROT
  272. \->LIST LINE
  273.       NEXT
  274.     \>>
  275.  
  276.   STATUS              @ displays the flight parameters
  277.     \<<
  278.       \<< + 1 \->GROB
  279. PICT 3 ROLLD REPL
  280.       \>> \-> s
  281.       \<< { # 54h
  282. # 0h } "Height: "
  283. ht s EVAL { # 54h
  284. # 6h } "VertV:  " v
  285. s EVAL { # 54h # Ch
  286. } "HorizV: " hv s
  287. EVAL { # 54h # 12h
  288. } "Fuel:   " fuel s
  289. EVAL
  290.       \>>
  291.     \>>
  292.  
  293.   GETKEY              @ processes keys
  294.     \<<
  295.       WHILE KEY
  296.       REPEAT
  297.         IF fuel 0 >   @ but only if we got fuel!
  298.         THEN
  299.           CASE DUP
  300. 72 ==
  301.             THEN -1
  302. 'hv' STO+ -1 'fuel'
  303. STO+
  304.             END DUP
  305. 74 ==
  306.             THEN 1
  307. 'hv' STO+ -1 'fuel'
  308. STO+
  309.             END DUP
  310. 63 ==
  311.             THEN
  312. thrust DUP NEG
  313. 'fuel' STO+ 'v'
  314. STO+
  315.             END
  316.           END
  317.         END DROP
  318.       END
  319.     \>>
  320.  
  321.   NEWC         @ get current screen coordiantes
  322.     \<< x R\->B 57 1 ht
  323. 57 MOD 57 / - * R\->B
  324. 2 \->LIST
  325.     \>>
  326.  
  327.   C\->V2       @ convert 2-element list to vector
  328.     \<< OBJ\-> DROP \->V2
  329.     \>>
  330.  
  331.   SHIP         @ GROB of the lander
  332. GROB 6 6 E13333E11212
  333.  
  334.   aflag        @ GROB of a flag
  335. GROB 7 7 F7747414F71010
  336.  
  337.   thrust 2     @ vertical thrust = -1/2 ag
  338.  
  339.   ag -4        @ acceleration due to gravity
  340.  
  341.   globals { \GSDAT     @ these are PURGEd
  342. CRASHv CRASHsl
  343. CRASHht CRASHx \GSPAR
  344. botCOORDS fuel x hv
  345. v ht }
  346.  
  347. END
  348.  
  349. @ END OF ASCII FILE
  350. END_RPL
  351.  
  352.  
  353. ---------------------------------------------------------------------------- 
  354.   Kevin Jessup, software engineer         bbwwbb@mixcom.com
  355.   marquette electronics                   (414)362-2020
  356.   Milwaukee, WI 
  357.  
  358.